/**
 * Created by python on 19-4-16.
 */
var vm = new Vue({
    el: '#big',
    delimiters: ['[[', ']]'], // 修改vue模板符号，防止与django冲突
    data: {
        host,
        username: sessionStorage.username || localStorage.username,
        user_id: sessionStorage.user_id || localStorage.user_id,
        avatar_url: sessionStorage.avatar_url || localStorage.avatar_url,
        token: sessionStorage.token || localStorage.token,
        nick_name: sessionStorage.nick_name || localStorage.nick_name,
        // 页面中需要使用到的数据，键值对
        title:'',
        labels:[],
        attenlabel:[],
    },
    //
    mounted: function () {
            //获取标签的相关内容
          axios.get(host + "/answers/labelsdetail/")

            .then(function (response ) {
                // console.log(response)
               vm.labels = response.data;
                console.log(vm.labels)
            } ),

          axios.get(host + "/answers/Labelsatten/",{
          headers: {
                    // 后台接收的JWT对格式有要求,'JWT'开头,空一格拼接字符串
                    'Authorization': 'JWT ' + this.token
                },
                responseType: 'json',})

            .then(function (response ) {
                // console.log(response)
               vm.attenlabel = response.data;
                console.log(vm.attenlabel)
            } )

    },
    methods: {
        logout: function() {
            sessionStorage.clear();
            localStorage.clear();
            location.href = './person-loginsign.html';
        },


        // 获取url路径参数
        get_query_string: function (name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURI(r[2]);
            }
            return null;
        },


        atten_operate:function (label_id) {

            axios.post(this.host + '/answers/Labelsatten/operate/', {
                    label_id:label_id,
                    user_id:vm.user_id,
                },{
                    // 向后端传递JWT token的方法
                    headers: {
                        // 后台接收的JWT对格式有要求,'JWT'开头,空一格拼接字符串
                        'Authorization': 'JWT ' + this.token
                    },
                    responseType: 'json'
                })
                    .then(response => {
                        console.log(response.data);
                        location.reload()
                    })
                    .catch(error => {
                        console.log(error.response.data);
                    })
        },


    },

});
